<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
</head>
<body>
<div id="app"></div>
<script>
    let SERVICE_BASE = 'https://cfcc-240e-47c-4ea8-28fe-35d6-ddc3-f0e6-a5fc.jp.ngrok.io' // 内网映射的服务端地址
    // 获取url参数
    function getQueryVariable() {
        let url = location.search; //获取url中"?"符后的字串
        let theRequest = new Object();
        if (url.indexOf("?") != -1) {
            let str = url.substr(1);
            strs = str.split("&");
            for (let i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    // 获取用户信息
    function getUserInfo() {
        let params = getQueryVariable();
        let openid = params.openid;
        if (!openid) { // 开始授权
            window.location.href = SERVICE_BASE + '/goAuth?webUrl=' + window.location.href;
        } else { // 授权结束
            let html = `头像：<img src="${params.headimgurl}">`
            let app = document.getElementById('app');
            app.innerHTML = html;
        }
    }

    window.addEventListener('load', function () {
        getUserInfo();
    })
</script>
</body>
</html>
